import type {FormRules} from "element-plus";
import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'

export const editData = {
  "projectNo": "2",
  "tmsProjectNo": "tms",
  "projectName": "test",
  "status": "0",
  "startTime": "2023-12-31T16:00:00.000Z",
  "endTime": "2024-01-22T16:00:00.000Z",
  "clinicalExperimentalPlanNo": "0001",
  "signCompanyName": "测试公司",
  "customerShortName": "jc",
  "customerNo": "001",
  "sponsor": "sbf",
  "businessType": "0",
  "projectLevel": "1",
  "contractNo": "",
  "outerContractNo": "0001",
  "bd": "bd",
  "pm": "pm",
  "irtAbutment": "1"
}


// 表单数据
export const initData = reactive({
  id: undefined,
  name: "",
  prefix: "",
  initValue: "",
  type: "",
  suffix: "",
  status: "",
  prefixDate: "",
  cycleDate: "",
  length: "",
});

// 表单配置项
export const formColumns = reactive([
  {
    xType: "Input",
    label: "序号名称",
    prop: "name",
    clearable: true,
    searchShow: true,
    labelWidth: '100',
    span: 6
  },
  {
    xType: "Input",
    label: "序号前缀",
    prop: "prefix",
    clearable: true,
    searchShow: true,
    span: 6
  },
  {
    xType: "Input",
    label: "初始值",
    prop: "initValue",
    clearable: true,
    searchShow: false,
    span: 6
  },
  {
    xType: "Select",
    label: "序号类型",
    prop: "type",
    clearable: true,
    searchShow: true,
    span: 6,
    options: getStrDictOptions(DICT_TYPE.SYSTEM_SEQ_TYPE)
  },
  {
    xType: "Input",
    label: "序号后缀",
    prop: "suffix",
    clearable: true,
    searchShow: false,
    span: 6
  },
  {
    xType: "Select",
    label: "状态",
    prop: "status",
    clearable: true,
    searchShow: false,
    span: 6,
    options: getStrDictOptions(DICT_TYPE.COMMON_STATUS)
  },
  {
    xType: "Input",
    label: "前缀日期",
    prop: "prefixDate",
    clearable: true,
    searchShow: false,
    span: 6
  },
  {
    xType: "Input",
    label: "周期",
    prop: "cycleDate",
    clearable: true,
    searchShow: false,
    span: 6
  },
  {
    xType: "Input",
    label: "取数长度",
    prop: "length",
    clearable: true,
    searchShow: false,
    span: 6
  },
]);

// 表单验证规则
export const formRules = reactive<FormRules>({
  // userName: [
  //   { required: true, message: "请输入名字", trigger: "blur" },
  //   { min: 2, max: 5, message: "名字长度在2-5个字", trigger: "blur" },
  // ],
  // projectNo: [
  //   {
  //     type: "email",
  //     message: "请输入正确的邮箱格式",
  //     trigger: ["blur", "change"],
  //   },
  // ],
  // tmsProjectNo: [
  //   {
  //     required: true,
  //     message: "请选择部门",
  //     trigger: "change",
  //   },
  // ],
});

// 表单搜索项目
export const searchFormData = (() => {
  const filterFormData = () => {
    let data = reactive<any>({});
    const newData = {};
    formColumns.forEach(item => {
      if (item.searchShow) {
        newData[item.prop] = "";
      }
    })
    return data = Object.assign(data, newData)
  }
  return filterFormData()
})()
// 表单搜索项目
export const searchFormColumns = (() => {
  const filterColumns = () => {
    const columns = [] as any;
    formColumns.forEach(item => {
      if (item.searchShow) {
        columns.push(item)
      }
    })
    return reactive<any>(columns)
  }
  return filterColumns()
})()


/***************************table 配置项****************************/
export const tableConfig = reactive({
  showSeletion: false, //是否支持多选
  showHandler: true, // 是否显示操作列
  showIndexColumn: false, // 是否显示索引
  isCheckMemory: true, // 是否需要跨页勾选
  showExpand: false, // 是否是展开行
  showAppend: false, // 插入至表格最后一行之后的内容， 如果需要对表格的内容进行无限滚动操作，可能需要用到这个 slot。 若表格有合计行，该 slot 会位于合计行之上
  indexLabel: "自定义序号", // 自定义索引名称
  handlerConfig: {
    align: "center",
    width: 120
  },
});

export const tableColumns = reactive([
  {
    prop: "name",
    label: "序号名称",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    prop: "prefix",
    label: "序号前缀",
    sortable: false,
    width: 120,
    align: "center"
  },
  {
    prop: "initValue",
    label: "初始值",
    sortable: false,
    width: 120,
    align: "center"
  },
  {
    prop: "type",
    label: "序号类型",
    sortable: false,
    width: 120,
    align: "center",
    dict: DICT_TYPE.SYSTEM_SEQ_TYPE
  },
  {
    prop: "suffix",
    label: "序号后缀",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    prop: "status",
    label: "状态",
    sortable: false,
    width: 120,
    align: "center",
    dict: DICT_TYPE.COMMON_STATUS
  },
  {
    prop: "prefixDate",
    label: "前缀日期",
    sortable: false,
    width: 180,
    align: "center"
  },
  {
    prop: "cycleDate",
    label: "周期",
    sortable: false,
    width: 120,
    align: "center"
  },
  {
    prop: "length",
    label: "取数长度",
    sortable: false,
    width: 120,
    align: "center"
  },
])
